from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

dr = webdriver.Firefox()
print(dr)
dr.get("https://www.12306.cn/index/")
lo = (By.ID, "fromStationText")
lo2 = (By.ID, "toStationText")
wa = WebDriverWait(driver=dr, timeout=10).until(EC.presence_of_element_located(lo))
inp = dr.find_element_by_id("fromStationText")
inp.click()
inp.send_keys("深圳北")
time.sleep(3)
inp.send_keys(Keys.ENTER)

time.sleep(2)

wa2 = WebDriverWait(driver=dr, timeout=10).until(EC.presence_of_element_located(lo2))
inp = dr.find_element_by_id("toStationText")
# inp.send_keys(Keys.ENTER)
inp.clear()
inp.send_keys("福建")
inp.send_keys(Keys.ENTER)

ti = '//*[@id="train_date"]'
tiu = (By.XPATH, ti)
wa3 = WebDriverWait(driver=dr, timeout=10).until(EC.presence_of_element_located(tiu))
inp = dr.find_element_by_xpath(ti)
inp.clear()
inp.send_keys("2023-05-01")
inp.send_keys(Keys.ENTER)

we1 = dr.find_element(By.XPATH, '//*[@id="search_one"]')
we1.send_keys(Keys.ENTER)

time.sleep(120)
dr.close()